package com.genius.adminmanager.group.controller;


import java.sql.SQLException;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.genius.adminmanager.group.service.GroupService;
import com.genius.adminmanager.other.entity.ResponseJson;
import com.genius.adminmanager.role.entity.RoleJson;
import com.genius.adminmanager.user.entity.UserJson;
import com.genius.workflow.util.ConnectionException;
import com.genius.workflow.util.DBClosedException;
import com.genius.workflow.util.DBTools;
import com.genius.workflow.util.DBUtils;


@Controller
public class GroupEditController {
	@Autowired
	@Qualifier("groupEditService")
    private GroupService groupEditService;
	
	/**
	 * 跳转到编辑页面
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@GetMapping("/adminmanager/group/toEdit")
	public String toAddMenu(){
		return "/views/adminmanager/group/edit";
	}
	
	@PostMapping("/adminmanager/group/edit")
	@ResponseBody
	public JSONObject edit(@RequestBody JSONObject json, HttpSession session){
		JSONObject response = new JSONObject();
    	response.put(ResponseJson.code, 0);
    	response = groupEditService.edit(json, response);
		return response;
	}
	/**
	 * 跳转到人员编辑页面
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@GetMapping("/adminmanager/group/toeditUser")
	public String toeditUser(){
		return "/views/adminmanager/group/editUser";
	}
	@PostMapping("/adminmanager/group/getUser")
	@ResponseBody
	public JSONObject getUser(@RequestBody JSONObject json){
		JSONObject response = new JSONObject();
		response.put(ResponseJson.code, 0);
		response = groupEditService.getUser(json, response);		
		return response;
	}
	@PostMapping("/adminmanager/group/editUser")
	@ResponseBody
	public JSONObject editUser(@RequestBody JSONObject json){
		JSONObject response = new JSONObject();
		response.put(ResponseJson.code, 0);
		response = groupEditService.editUser(json, response);		
		return response;
	}
	@PostMapping("/adminmanager/group/editSupervisor")
	@ResponseBody
	public JSONObject editSupervisor(@RequestBody JSONObject json){
		JSONObject response = new JSONObject();
		response.put(ResponseJson.code, 0);
		response = groupEditService.editSupervisor(json, response);		
		return response;
	}
}
